<template>
	<view class="contain">
		<view class="mySearch">
			<my-search bgColor="red" @myclick="gotoSearch"></my-search>
		</view>
		<view class="box">
			
			<scroll-view class="left-scrollview" scroll-y="true" :style="{ height: wh +'px'}">
			<!-- <view class="left-scroll-view-item active">{{cateList[0].cat_name}}</view>
			
			<view v-for="(item,index) in cateList" :key="index" v-if="index != 0">
				<view class="left-scroll-view-item">{{item.cat_name}}</view>
			</view> -->
			<block v-for="(item,i) in cateList" :key="i">
				<view @click="activeChange(i)" :class="['left-scroll-view-item',i===active?'active':'']">{{item.cat_name}}</view>
			</block>
			</scroll-view>
			
			<scroll-view  scroll-y="true" :style="{ height: wh +'px'}" :scroll-top="scrollTop">
				
				<view class="cate-lv2" v-for="(item2,i2) in cateLevel2" :key='i2'>
					<view class="cate-lv2-title">
						/ {{item2.cat_name}} /
					</view>
					<view class="cate-lv3-list">
						<view @click="gotoCateList(item3)" class="cate-lv3-item" v-for="(item3,i3) in item2.children" :key="i3">
							<image src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png" ></image>
							<!-- <image src="item3.cat_icon" style="width: 100px;" mode="widthFix"></image> -->
							
							<text>{{item3.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
	

</template>

<script>

	// import mySearch from "../../components/my-search.vue"
	
	export default {
		// components: {
		// 	mySearch
		// },
	
		data() {
			return {
				wh:0,
				cateList:[],
				cateLevel2:[],//二级分类数组
				active:0,
				scrollTop:0
			};
		},
		onLoad(){
			const sysInfo = uni.getSystemInfoSync();
			this.wh = sysInfo.windowHeight - 50;
			// console.log(sysInfo)
			this.getCateList()
		},
		methods:{
			gotoSearch(){
				uni.navigateTo({
					url:"../../subpkg/search/search"
				})
				console.log("cate gotoSearch ")
			},
			async getCateList(){
			const {data :res} = await uni.$http.get('/api/public/v1/categories')
				 if (res.meta.status !== 200) return uni.$showMsg()
				 console.log(res.message)
				this.cateList = res.message;
				this.cateLevel2 = this.cateList[this.active].children;
			},
			activeChange(e){
				this.active = e;
				this.cateLevel2 = this.cateList[this.active].children;
				this.scrollTop = this.scrollTop == 0?1:0;
				
			},
			gotoCateList(item) {
				uni.navigateTo({
					url:'../../subpkg/goods_detail/goods_detail?cid='+item.cat_id
				})
			}
		}
		
	}
	
</script>

<style lang="scss">
	// my-search {
	// 	width: 100%;
	// 	height: 50px;
	// }
	.cate-lv3-list {
		display: flex;
		flex-wrap: wrap;
	}
	.cate-lv3-item {
		display: flex;
		flex-direction: column;
		 align-items:center;
		 image {
			 width: 200rpx;
			 height: 40px;
			  mode:'widthFix'
		 }
		 text{
			 font-size: 12px;
		 }
	}
	.cate-lv2-title {
		width: 100%;
		// line-height: 30px;
		text-align: center;
		font-size: 12px;
		margin-top: 20px;

	}
	.left-scrollview {
		width: 150rpx;
		background-color: "#c00000";
	}
	
	.left-scroll-view-item {
		background-color:#F7f7f7;
		line-height: 60px;
		font-size: 12px;
		text-align: center;
		position: relative;
		
		&.active {
			background-color: #FFFFFF;
			&::before {
				content: '';
				display: block;
				background-color: #e00000;
				width: 3px;
				height: 30px;
				top: 50%;
				position: absolute;
				transform: translateY(-50%);				
			}
		}
	}
	
.box {
	display: flex;
}
</style>
